package com.lzh.o2o.util;

import javax.servlet.http.HttpServletRequest;

/** 
* @author  haohao: 
* @date 创建时间：2018年9月9日 下午10:03:09 
* @version 1.0 
* @parameter 
* @since  
* @return  
*/
public class HttpServletRequestUtil {

	//将request中的请求的字符串转换成整型,如果失败，转化成-1
	public static int getInt(HttpServletRequest request,String key){
		try{
			return Integer.decode(request.getParameter(key));
		}catch(Exception e){
			return -1;
		}
	}
	//将request中的请求的字符串转换成长整型,如果失败，转化成-1

	public static Long getLong(HttpServletRequest request,String key){
		try{
			return Long.valueOf(request.getParameter(key));
		}catch(Exception e){
			return -1L;
		}
	
	}
	
	//将request中的请求的字符串转换成浮点型,如果失败，转化成-1

	public static Double getDouble(HttpServletRequest request,String key){
		try{
			return Double.valueOf(request.getParameter(key));
		}catch(Exception e){
			return -1d;
		}
	}
	
	//将request中的请求的字符串转换成布尔型,如果失败，转化成-1

	public static boolean getBoolean(HttpServletRequest request,String key){
		try{
			return Boolean.valueOf(request.getParameter(key));
		}catch(Exception e){
			return false;
		}
	}
	
	public static String getString(HttpServletRequest request,String key){
		try{
			String result = request.getParameter(key);
			if(result != null){
				result=result.trim(); 
			}
			if("".equals(result)){
				result =null;
			}
			return result;
		}catch(Exception e){
			return null;
		}
	}
}
